/*
 * @Description:
 * @Author: chenju
 * @Date: 2021-11-08 15:37:26
 * @LastEditors: qingyang
 * @LastEditTime: 2023-07-25 16:56:02
 */
import { get, post } from '@/utils/http';
import {
  AddEmissionParams,
  GetEmissionFactorParams,
  GetEmissionFactorResult,
  GetEmissionListResult,
  GetEmissionOptionsResult,
  GetFactorOptionsResult,
  GetRelationListParams,
  GetRelationListResult,
  UpdateEmissionStatusParams,
  IAddRelation,
  IUpdateRelation
} from './model/relationshipModel';
enum Api {
  // 新增关联关系
  ADD_RELATION = '/inventory/emissionRelation/saveRelation',
  // 修改关联关系
  UPDATE_RELATION = '/inventory/emissionRelation/updateRelation',
  // 删除关联关系
  DEL_RELATION = '/inventory/emissionRelation/deleteRelation',
  // 关联关系查询
  GET_RELATION_LIST = '/inventory/emissionRelation/pageRelations',
  //TODO 以下接口之后如果多余的需要删除
  // 排放结构节点启动停用
  UPDATE_EMISSION_STATUS = '/inventory/emissionFramework/updateState',
  // 排放结构（关联关系）节点添加
  ADD_EMISSION = '/inventory/emissionFramework/save',
  // 获取目录树
  GET_EMISSION_LIST = '/inventory/emissionFramework/list',
  // 能源/燃料选择
  GET_FACTOR_OPTIONS = '/inventory/inventoryFactor/listFactor',
  // 排放源选择
  GET_EMISSION_OPTIONS = '/inventory/emissionSource/listName',
  // 关联关系批量新增弹窗数据获取
  GET_EMISSION_FACTOR = '/inventory/inventoryFactor/emissionFactor'
}

// 添加关联关系
export const addRelation = (params: IAddRelation): Promise<void> => post(Api.ADD_RELATION, params);
// 修改关联关系
export const updateRelation = (params: IUpdateRelation): Promise<void> =>
  post(Api.UPDATE_RELATION, params);

// 关联关系查询
export const getRelationList = (params: GetRelationListParams): Promise<GetRelationListResult> =>
  get(Api.GET_RELATION_LIST, params);

// 排放结构节点启动停用
export const updateEmissionStatus = (params: UpdateEmissionStatusParams): Promise<void> =>
  post(Api.UPDATE_EMISSION_STATUS, params);

// 排放结构（关联关系）节点添加
export const addEmission = (params: AddEmissionParams): Promise<any> =>
  post(Api.ADD_EMISSION, params);

// 获取目录树
export const getEmissionTree = (): Promise<GetEmissionListResult[]> =>
  get(Api.GET_EMISSION_LIST, {});

// 能源/燃料选择
export const getFactorOptions = (factorName: string): Promise<GetFactorOptionsResult[]> =>
  get(Api.GET_FACTOR_OPTIONS, { factorName });

// 获取排放源选择
export const getEmissionOptions = (): Promise<GetEmissionOptionsResult[]> =>
  get(Api.GET_EMISSION_OPTIONS, {});

// 关联关系批量新增弹窗数据获取
export const getEmissionFactor = (
  params: GetEmissionFactorParams
): Promise<GetEmissionFactorResult> => get(Api.GET_EMISSION_FACTOR, params);

// 删除关联关系
export const delRelation = (relationNo: string): Promise<void> =>
  post(Api.DEL_RELATION, { relationNo });
